package com.web.base.user.dao;

import org.springframework.stereotype.Repository;

import com.blue.jdbc.BaseDao;
import com.web.base.user.model.Office;

/**
 * 部门数据库访问
 * 
 * @author 代码由 blue-code 框架生成
 * @since 1.0 2017年04月16日
 */
@Repository
public class OfficeDao extends BaseDao<Office>
{
	public OfficeDao()
	{
	}
	
	@Override
	protected void query(StringBuilder sql, Office param)
	{
		if (param != null)
		{
			if (param.getParentId() != null && param.getParentId() > 0)
				sql.append(" and a.parent_id=:parentId");
				
			if (param.getCode() != null && !param.getCode().isEmpty())
				sql.append(" and a.code=:code");
				
			if (param.getName() != null && !param.getName().isEmpty())
			{
				sql.append(" and a.name like :name");
				param.setName("%" + param.getName() + "%");
			}
			
			if (param.getType() != null)
				sql.append(" and a.type=:type");
				
			if (param.getState() != null)
				sql.append(" and a.state=:state");
				
		}
		sql.append(" order by a.id");
	}
	
}
